package edu.hawaii.duedates.messenger;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import org.junit.Test;
import edu.hawaii.duedates.messenger.IMessenger.MessageType;
import edu.hawaii.duedates.messenger.IMessenger.OutputType;

/**
 * Tests the Messenger class.
 * 
 * @author Ronn Reeves and Robin Raqueno
 */
public class TestMessenger {
  
  /**
   * Tests the Messenger constructor.
   */
  @Test
  public void testConstructor() {
    Messenger msg = new Messenger();
    assertEquals("testConstructor() failed.", msg.getOutFormat(), OutputType.CONSOLE);
    assertEquals("testConstructor() failed.", msg.getMessage(), "");
  }

  
  /**
   * Tests the Email constructor.
   */
  @Test (expected = AssertionError.class)
  public void testEmailConstructor() {
    Email email = new Email("username@domain.ext", "mail.domain.ext", "test");
    email.send();
    
    fail("Sending email failed.");
  }
  
  
  /**
   * Tests the accessor and mutator methods.
   */
  @Test
  public void testProperties() {
    Messenger msg = new Messenger();
    msg.setOutFormat(OutputType.EMAIL);
    msg.setVerbose(Boolean.TRUE);
    msg.append(MessageType.SIMPLE, "Test");
    
    assertEquals("getOutFormat() failed.", msg.getOutFormat(), OutputType.EMAIL);
    assertTrue("isVerbose() failed.", msg.isVerbose());
    assertEquals("toString() failed.", msg.toString(), "Test");
  }
  
  
  /**
   * Tests the behavioral methods.
   */
  @Test (expected = StringIndexOutOfBoundsException.class)
  public void testBehaviors() {
    Messenger msg = new Messenger();
    msg.append(MessageType.SIMPLE, "Test");
    msg.report();
    msg.report("username@domain.ext", "mail.domain.ext");
    fail("report(String, String) failed.");
  }
  
  
  /**
   * Tests the Enumerated Types of IMessenger.
   */
  @Test
  public void testEnumTypes() {
    for (MessageType mt : MessageType.values()) {
      assertEquals("valueOf(" + mt.name() + ") OutputType failed.", 
        mt, MessageType.valueOf(mt.name()));
    }
    
    for (OutputType ot : OutputType.values()) {
      assertEquals("valueOf(" + ot.name() + ") OutputType failed.", 
        ot, OutputType.valueOf(ot.name()));
    }
  }
}
